﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2016-2018 Jean-Marc VIGLINO, 
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Texture filter </title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="Crop and mask filter on an ol map or layer." />
  <meta name="keywords" content="ol3, filter, crop, mask" />

  <link rel="stylesheet" href="../style.css" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
  <!-- FontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
  
  <!-- ol-ext -->
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>
  <!-- Extra features: textures -->
  <script type="text/javascript" src="../../dist/extra/TextureImage.js"></script>

  <style>
    input[type="range"] 
    {	vertical-align: middle;
    }
    input[type="number"] 
    {	width:4em;
    }
  </style>

</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Texture filter</h1>
  </a>
  <div class="info">
    <i>ol.filter.Texture</i> add a texture effect on the map. 
  </div>

  <!-- Map div -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div class="options" >
    <ul><li>
      Texture:
      <select id="texture" onchange="setFilter()">
        <option value="wood">wood</option>
        <option value="stone">stone</option>
        <option value="rust">rust</option>
        <option value="metal">metal</option>
        <option value="cardboard">cardboard</option>
        <option value="notebook">notebook</option>
        <option value="https://opengameart.org/sites/default/files/parchment-gold.png.preview.jpg">parchemin</option>
        <option value="https://opengameart.org/sites/default/files/WhiteIrregular_T.jpg">paving</option>
      </select>
    </li><li>
      <input id="active" type="checkbox" checked="checked" /><label for="active"> active</label>
    </li><li>
      <input id="rotate" type="checkbox" checked="checked" /><label for="rotate"> rotate with view</label>
    </li><li>
      Opacity: <input id="opacity" type="range" min="0" max="1" step="0.1" value="0.7" />
    </li></ul>
  </div>

  <script type="text/javascript">
    $("input").on('change', setFilter);

    var osm = new ol.layer.Tile({ source: new ol.source.OSM() });
    // The map
    var map = new ol.Map({
      target: 'map',
      view: new ol.View({
        zoom: 8,
        center: [247044, 6549736.]
      }),
      layers: [
        osm
      ]
    });

    // Custom filter
    var filter = new ol.filter.Texture();
    osm.addFilter(filter);

    function setFilter() {
      filter.setActive($("#active").prop('checked'));
      filter.setFilter({
        src: $("#texture").val(), 
        rotateWithView: $("#rotate").prop('checked'),
        opacity: Number($("#opacity").val()) 
      });
    }
    setFilter();

  </script>
</body>
</html>